package org.example.jcclubsubjectdomain.basic.service.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.example.jcclubsubjectdomain.basic.convet.SubjectInfoBOConverter;
import org.example.jcclubsubjectdomain.basic.entity.SubjectInfoBO;
import org.example.jcclubsubjectdomain.basic.service.SubjectInfoDomainService;
import org.example.jcclubsubjectdomain.handler.SubjectTypeHandler;
import org.example.jcclubsubjectdomain.handler.SubjectTypeHandlerFactory;
import org.example.jcclubsubjectinfra.basic.entity.SubjectInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 啊昌
 * @date 2025/4/12 23:49
 * SubjectInfoDomainServiceImpl TODO
 */
@Service
@Slf4j
public class SubjectInfoDomainServiceImpl implements SubjectInfoDomainService{

	@Resource
	private SubjectTypeHandlerFactory factory;


	@Override
	public Boolean add(SubjectInfoBO subjectInfoBO) {
//
		if (log.isInfoEnabled()) {
			log.info("SubjectInfoDomainServiceImpl.add.bo:{}", JSON.toJSONString(subjectInfoBO));
		}
//		将 bo 转换为 entity
		SubjectInfo subjectInfo = SubjectInfoBOConverter.INSTANCE.convertBOToEntity(subjectInfoBO);
		subjectInfo.setId(subjectInfoBO.getId());
//		根据添加的题型类别 获取到 不同 的执行器 进行处理不同的add方法
//		工厂 + 策略模式实现
		SubjectTypeHandler handler = factory.getHandler(subjectInfoBO.getSubjectType());
		handler.add(subjectInfoBO);
		return null;
	}
}
